package tv.accedo.achi.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import tv.accedo.achi.dao.AchiDao;
import tv.accedo.achi.model.Achi;

@Component
public class AchiService {

	private AchiDao achiDao; //injection
	private Achi achi; //injection
	
	public String getJsonAchiByAchisn(String achi_sn) {
		achi = achiDao.getAchiByAchisn(achi_sn); 
		String jsonAchi = "{achi_desc:'" + achi.getAchi_desc() + "'}";
		return jsonAchi; 
	}
	
	public String getJsonAchisByAppsn(String app_sn) {
		String jsonAchis = "]}"; 
		List<Achi> achiList = new ArrayList<Achi>(); 
		achiList = achiDao.getAchisByAppsn(app_sn); 
		for(Iterator<Achi> iter = achiList.iterator(); iter.hasNext(); ) {
			achi = iter.next(); 
			jsonAchis = "{achi_sn:'" + achi.getAchi_sn() + "',achi_name:'"
					+ achi.getAchi_name() + "'},"
					+ jsonAchis;
		}
		jsonAchis = "{achis:[" + jsonAchis;
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		System.out.println(jsonAchis); 
		return jsonAchis; 
	}

	public Achi getAchi() {
		return achi;
	}

	@Resource
	public void setAchi(Achi achi) {
		this.achi = achi;
	}

	public AchiDao getAchiDao() {
		return achiDao;
	}

	@Resource
	public void setAchiDao(AchiDao achiDao) {
		this.achiDao = achiDao;
	}
}
